<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>无敌冰图床</title>
    <link href="https://fonts.font.im/css?family=Noto+Sans+SC:400,500|Roboto:300,400,500" rel="stylesheet">
    <style>
        :root {
            --primary-color: #1890ff;
            --hover-color: #40a9ff;
            --success-color: #52c41a;
            --error-color: #ff4d4f;
            --shadow-light: 0 4px 6px rgba(0, 0, 0, 0.05);
            --shadow-medium: 0 6px 16px rgba(0, 0, 0, 0.1);
        }

        body { 
            font-family: 'Noto Sans SC', 'Roboto', sans-serif; 
            max-width: 800px;
            margin: 2rem auto;
            padding: 0 1.5rem;
            background: #f0f2f5;
        }

        .upload-box {
            background: white;
            border: 2px dashed var(--primary-color);
            padding: 3rem 2rem;
            text-align: center;
            border-radius: 12px;
            box-shadow: var(--shadow-light);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .upload-box:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow-medium);
            border-color: var(--hover-color);
        }

        h2 {
            color: #1f1f1f;
            font-weight: 500;
            margin-bottom: 1.5rem;
            font-size: 1.8rem;
            position: relative;
            z-index: 1;
        }

        .preview-container {
            margin: 1.5rem 0;
            min-height: 150px;
            border-radius: 8px;
            overflow: hidden;
            position: relative;
            transition: all 0.3s;
        }

        .preview-image {
            width: 100%;
            height: auto;
            max-height: 300px;
            object-fit: contain;
            border-radius: 8px;
            box-shadow: var(--shadow-light);
            display: none;
        }

        .file-input-wrapper {
            position: relative;
            margin: 1.5rem 0;
        }

        input[type="file"] {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
            cursor: pointer;
        }

        .custom-file-input {
            display: inline-block;
            padding: 1.2rem 2.5rem;
            background: linear-gradient(135deg, var(--primary-color), var(--hover-color));
            color: white;
            border-radius: 6px;
            transition: all 0.3s;
            box-shadow: var(--shadow-light);
        }

        .custom-file-input:hover {
            transform: translateY(-1px);
            box-shadow: var(--shadow-medium);
        }

        button {
            background: linear-gradient(135deg, var(--primary-color), var(--hover-color));
            color: white;
            border: none;
            padding: 1rem 2rem;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s;
            font-size: 1rem;
            letter-spacing: 0.5px;
            box-shadow: var(--shadow-light);
            margin-top: 1rem;
        }

        button:hover {
            transform: translateY(-1px);
            box-shadow: var(--shadow-medium);
        }

        .result {
            margin: 2rem 0;
            padding: 1.25rem;
            border-radius: 8px;
            background: white;
            box-shadow: var(--shadow-light);
            min-height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s;
        }

        .loading {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            color: var(--primary-color);
        }

        .loading::after {
            content: "";
            width: 16px;
            height: 16px;
            border: 2px solid #ddd;
            border-top-color: var(--primary-color);
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        @media (max-width: 480px) {
            .upload-box {
                padding: 2rem 1rem;
            }
            .preview-image {
                max-height: 200px;
            }
        }
    </style>
</head>
<body>
    <div class="upload-box">
        <h2>📚 无敌冰图床</h2>
        <div class="preview-container">
            <img src="#" class="preview-image" alt="图片预览">
        </div>
        <form action="upload.php" method="post" enctype="multipart/form-data">
            <div class="file-input-wrapper">
                <input type="file" name="comic_file" accept="image/*" required id="fileInput">
                <div class="custom-file-input">选择图片文件</div>
            </div>
            <button type="submit">✨ 立即上传</button>
        </form>
    </div>
    <div class="result" id="result"></div>
    
    <script>
        // 图片预览功能
        const fileInput = document.getElementById('fileInput');
        const previewImage = document.querySelector('.preview-image');

        fileInput.addEventListener('change', function(e) {
            const file = e.target.files[0];
            if (file && file.type.startsWith('image/')) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    previewImage.style.display = 'block';
                    previewImage.src = e.target.result;
                }
                reader.readAsDataURL(file);
            }
        });

        // 上传处理
        document.querySelector('form').addEventListener('submit', async (e) => {
            e.preventDefault();
            const formData = new FormData(e.target);
            const resultDiv = document.getElementById('result');
            
            resultDiv.innerHTML = '<div class="loading">文件上传中...</div>';
            resultDiv.style.background = 'white';
            resultDiv.style.color = 'inherit';

            try {
                const response = await fetch('upload.php', {
                    method: 'POST',
                    body: formData
                });
                const data = await response.text();
                resultDiv.innerHTML = `✅ ${data}`;
                resultDiv.style.background = 'var(--success-color)';
                resultDiv.style.color = 'white';
                previewImage.style.display = 'none';
                fileInput.value = '';
            } catch (error) {
                resultDiv.innerHTML = `❌ 上传失败：${error.message}`;
                resultDiv.style.background = 'var(--error-color)';
                resultDiv.style.color = 'white';
            }
        });
    </script>
</body>
</html>